#include "stdafx.h"
#include "crHttpTimeout.h"

NS_CR_BEGIN

#define NOMINMAX
#undef max
#undef min

namespace http
{

	long Timeout::Milliseconds() const
	{
		static_assert(std::is_same<std::chrono::milliseconds, decltype(ms)>::value,
			"Following casting expects milliseconds.");

		if (ms.count() > std::numeric_limits<long>::max()) {
			throw std::overflow_error("cpr::Timeout: timeout value overflow: " +
				std::to_string(ms.count()) + " ms.");
		}
		if (ms.count() < std::numeric_limits<long>::min()) {
			throw std::underflow_error("cpr::Timeout: timeout value underflow: " +
				std::to_string(ms.count()) + " ms.");
		}

		return static_cast<long>(ms.count());
	}

}

NS_CR_END